package com.creditease.tmsp.common.service;

import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;

import com.creditease.tmsp.common.persistence.MyBatisBaseDao;
import com.github.miemiedev.mybatis.paginator.domain.PageBounds;
import com.google.common.collect.Lists;

//@Service
//@Transactional(readOnly = true)
public abstract class MyBatisBaseService<T> {


	public abstract MyBatisBaseDao<T> getDao();
	
	public T getById(String id) {
		return this.getDao().getById(id);
	}
	
	public List<T> query(PageBounds pageBounds,Map<String,Object> params) {
		return this.getDao().query(pageBounds,params);
	}
	
	public List<T> find(Map<String,Object> params){
		return this.getDao().find(params);
	}
	
	public void save(T t){
		this.getDao().save(t);
	}
	

	public void update(T t){
		this.getDao().update(t);
	}
	
	public void deleteById(String id){
		
		this.getDao().deleteById(id);
	}
	
	public int delete(String ids){
		return this.getDao().delete(getIdList(ids));
	}

	
	protected List<String> getIdList(String ids) {
		List<String> idList = Lists.newArrayList();
		if(StringUtils.isNotBlank(ids)) {
			ids = ids.trim().replace("　", ",").replace(" ", ",").replace("，", ",");
			String[] arrId = ids.split(",");
			for(String id:arrId) {
				if(StringUtils.isNotBlank(id)) {
					idList.add(id);
				}
			}
		}
		return idList;
	}
	
}
